package csu.web.mypetstore.web.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;

public class SignOutServlet extends HttpServlet {
    public static final String MAIN = "/WEB-INF/jsp/catalog/main.jsp";

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession httpSession = req.getSession();
//        List<Log> logList = new ArrayList<>();
//        logList = (List<Log>) httpSession.getAttribute("logList");
//        LogService logService = new LogService();
//        logService.updateLog(logList, "Log out of the pet store.", (Account) httpSession.getAttribute("account"));
        httpSession.removeAttribute("account");
        httpSession.removeAttribute("cart");
//        httpSession.removeAttribute("logList");
        httpSession.removeAttribute("message");
        req.getRequestDispatcher(MAIN).forward(req, resp);
    }
}
